<?php
class pro_setup_stock_model extends MY_Model {
	var $nama_tabel = 'ADMIN_PRIMKOKAS.PRO_SETUP_STOCK';

	function getApp() {
		$ls_sql	= "	SELECT	NAMA_CABANG value,
							NAMA_CABANG display
					FROM	ADMIN_PRIMKOKAS.PRO_SETUP_CABANG
					ORDER BY NAMA_CABANG";
					
		$result	= $this->db->query($ls_sql);
		if($result->num_rows() > 0){
			return $result->result_array();
		}else{
			return array();
		}
	}
	
	function GetJSON()
	{
		$ls_sql	= "	SELECT	*
					FROM	pro_setup_stock 
					WHERE	(UPPER(kode_barang) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_barang) LIKE '%".strtoupper(post('keyword'))."%'
							)
					ORDER BY ".(post('sort')=='' ? 'id_barang' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
		return json_encode( $this->paging($ls_sql) );
	}

	function GetJSON2()
	{
		$ls_sql	= "	SELECT	*
					FROM	pro_setup_stock 
					WHERE   (UPPER(kode_barang) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_barang) LIKE '%".strtoupper(post('keyword'))."%'
							)
					ORDER BY ".(post('sort')=='' ? 'id_barang' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
		return json_encode( $this->paging($ls_sql) );
	}

	function Add($arr_data){
		$this->db->insert($this->nama_tabel, $arr_data);
	}

	function Update($arr_data, $arr_rule){
		$a = $this->db->update($this->nama_tabel, $arr_data, $arr_rule);
	}

	function DeleteSingle($arr_rule) {
		try {
			if(	intval($this->get_data("SELECT COUNT(1) FROM ADMIN_PRIMKOKAS.PRO_SETUP_STOCK WHERE KODE_BARANG = '".$arr_rule['kode_barang']."'"))<=0)
			{
				return $this->error_delete.' [id: '.$arr_rule['kode_barang']."]<br /> SELECT COUNT(1) FROM ADMIN_PRIMKOKAS.PRO_SETUP_STOCK WHERE kode_barang = '".$arr_rule['kode_barang']."'";
			}else{
				$this->db->delete('ADMIN_PRIMKOKAS.PRO_SETUP_STOCK', array('kode_barang' => $arr_rule['kode_barang']));
				return '';
			}
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}

}
?>